

program deflat
args deflateVar valg aarvar base


qui sum `aarvar'
local styear=r(min)
local endyear=r(max)

if `valg'==1 {
    local cpi1980 =	2396
	local cpi1981 =	2677
	local cpi1982 =	2948
	local cpi1983 =	3152
	local cpi1984 =	3350
	local cpi1985 =	3507
	local cpi1986 =	3636
	local cpi1987 =	3782
	local cpi1988 =	3953
	local cpi1989 =	4142
	local cpi1990 =	4251
	local cpi1991 =	4353
	local cpi1992 =	4445
	local cpi1993 =	4500
	local cpi1994 =	4590
	local cpi1995 =	4686
	local cpi1996 =	4785
	local cpi1997 =	4890
	local cpi1998 =	4980
	local cpi1999 =	5104
	local cpi2000 =	5253
	local cpi2001 =	5377
	local cpi2002 =	5507
	local cpi2003 =	5622
	local cpi2004 =	5687
	local cpi2005 =	5790
	local cpi2006 =	5900
	local cpi2007 =	6001
	local cpi2008 =	6205
	local cpi2009 =	6287
	local cpi2010 =	6432
	local cpi2011 =	6609
	local cpi2012 = 6768
    local cpi2013 = 6821
	local cpi2014 = 6860
	local cpi2015 = 6891
	local cpi2016 = 6909
	local cpi2017 = 6988
	local cpi2018 = 7045
	local cpi2019 = 7098
	local cpi2020 = 7128
	local cpi2021 = 7260

}

* Nominel BNP.

else {
	local y=1980
   foreach c of local 	4009 4408 5034 5546 6121 6640 7126 7484 7778 8217 8556 8906 9230 9285 9933 10365 10880 11461 11860 12415 13269 13715 14103 14368 15060 15860 16823 17388 18015 17221 18109 18469 18950 19297 19812 20364 21078 21930 22533 23110 23239 25042 {
   	
   	local cpi`y' = `c'
   local y=`y'+1
   }
}

*Prim�r person

tempvar r
gen `r' = .
 forvalues yr = `styear'(1)`endyear' {
	replace `r' = `deflateVar' * (`cpi`base'' / `cpi`yr'') if `aarvar'==`yr' 
}
replace `deflateVar'=`r'
drop `r'

end 
